package cn.utils;


import cn.dto.Basiclfor;
import cn.dto.UserDefinedAttribute;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;


import java.io.File;
import java.io.FileInputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class Surface {

    public ArrayList<Basiclfor> test(String getxlsx) {


        Workbook workbook = null;
        File Inputfile = new File(getxlsx);
        // File outputfile = new File("C:\\Users\\Administrator\\Desktop\\car.txt");
        ArrayList<Basiclfor> list = new ArrayList<>();


        // Unable to recognize OLE stream ss不支持xlsx格式 支持xls格式

        try {
            //字符输入流，读取表格
            FileInputStream fileInputStream = new FileInputStream(Inputfile);
            workbook = Workbook.getWorkbook(fileInputStream);
            // FileOutputStream fileOutputStream = new FileOutputStream(outputfile);
            // BufferedOutputStream bw = new BufferedOutputStream(fileOutputStream); //输出语句
            //读取第一个单元薄
            Sheet readfirst = workbook.getSheet(0);
            //有效行
            int rows = readfirst.getRows();
            //有效列
            int clomns = readfirst.getColumns();
            System.out.println("row:" + rows);
            System.out.println("clomns:" + clomns);

            for (int i = 1; i < rows; i++) {
                Cell[] cells = readfirst.getRow(i); //循环得到每一行的单元格对象


                //根据每一个单元格对象的到里面的值
                String sensorId = cells[0].getContents().replaceAll(" ", "");
                if (sensorId == "") break;
                String dataCode = cells[1].getContents().replaceAll(" ", "");

                //获取时间
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date();
                String format = dateFormat.format(date);


                UserDefinedAttribute userDefinedAttribute = new UserDefinedAttribute();

                Basiclfor basiclfor = new Basiclfor(sensorId, dataCode, format,userDefinedAttribute);
                list.add(basiclfor);


            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
